class Container{
    static of(value){
        return new Container(value)
    }
    constructor(value){
        this._value = value
    }
    map(fn){
        return Container.of(fn(this._value))
    }
}

class MayBe{
    static of(x){
        return new MayBe(x)
    }
    isNothing(){
        return this._value === null || this._value === undefined
    }
    constructor(x){
        this._value = x
    }
    map(fn){
        return this.isNothing()?this:MayBe.of(fn(this._value))
    }
}

const fp = require('lodash/fp')
const { parseInt } = require("lodash")

let maybe = MayBe.of([5,6,1])
//第一题
let ex1 = () =>{
    let fn = fp.flowRight(fp.map(fp.add(num)))
    return maybe.map(fn)  
}
console.log(ex1(3))
//第二题

let xs = Container.of(['do','ray','me','fa','so','la','ti','do'])
let ex2 = () => {
    return xs.map(fp.first)._value
}
console.log(ex2())
//第三题
let ex3 = () => {
    return safeProp('name',user).map(fp.first)._value
}
console.log(ex3()) 
//第四题
let  ex4 = function(n){
    let m1 = new MayBe(n)
    let m2 = m1.map(parseInt)
    return m2._value
}
ex4()  
ex4(1) 